[deps.host]
dynamic-toolchain

[mirrors]
http://www.cpan.org/src/5.0/perl-5.16.3.tar.bz2

[main]
filesize=13724906
sha512=c30cda0af9463942e40b5d70a95e69b0640bf0b79d9d9dfa1a61d9d8b9ee05f553fd240be4c8b3c60a1def66c80453e49e865c27d3dd0b686f5c004e1ff58d92

[build]
VERSION=5.16.3

#workaround for issue #185
patch -p1 < "$K"/perl-arm-gcc473bug.patch

# with empty prefix, perl will disregard the prefix parameters entirely, failing to build
[ -z "$butch_prefix" ] && butch_prefix=/

debug_flags=
[ "$DEBUGBUILD" = "1" ] && debug_flags="-Doptimize=-O0 -DEBUGGING=-g"


sed -i 's,-fstack-protector,-fnostack-protector,g' ./Configure

CC="gcc" ./Configure -des \
  -Accflags="-D_GNU_SOURCE -D_BSD_SOURCE -fPIC $optcflags" \
  -Aldflags="$optldflags" \
  -Dprefix="$butch_prefix" -Dvendorprefix="$butch_prefix" \
  -Dinstallprefix="$butch_install_dir" \
  -Dprivlib="$butch_prefix"/lib/perl5/core_perl \
  -Darchlib="$butch_prefix"/lib/perl5/core_perl \
  -Dsitelib="$butch_prefix"/lib/perl5/site_perl \
  -Dsitearch="$butch_prefix"/lib/perl5/site_perl \
  -Dvendorlib="$butch_prefix"/lib/perl5/vendor_perl \
  -Dvendorarch="$butch_prefix"/lib/perl5/vendor_perl \
  -Dscriptdir="$butch_prefix"/bin \
  -Dsitescript="$butch_prefix"/bin \
  -Dvendorscript="$butch_prefix"/bin \
  -Dinc_version_list=none $debug_flags \
  -Dman1dir="$butch_prefix"/share/man/man1perl -Dman1ext=1perl \
  -Dman3dir="$butch_prefix"/share/man/man3perl -Dman3ext=3perl || exit 1

make -j$MAKE_THREADS || exit 1
make install || exit 1

dest="$butch_install_dir""$butch_prefix"

if [ -n "$butch_install_dir" ] ; then

  # remove hardcoded DESTDIR from config, which gets used by ExtUtils::MakeMaker
  # and leads to perl stuff being installed into PACKAGEDESTDIR/PERLDESTDIR
  # - which of course causes breakage.

  sed -i s@"$butch_install_dir"@@g "$dest"/lib/perl5/core_perl/Config_heavy.pl || exit 1

  # perl manpages take 20 MB, that's a third of its entire size.
  # as long as nobody needs them, we will remove them.
  rm -rf "$dest"/share/man

fi

# replace duplicated perl binary with symlink
ln -sf perl$VERSION "$dest"/bin/perl


